<?php
declare (strict_types=1);

// +----------------------------------------------------------------------
// | SCApi
// +----------------------------------------------------------------------
// | 版权所有 2021~2022 贾二小 [ http://www.ipsoul.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://www.ipsoul.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// | 免费声明 ( http://doc.ipsoul.com/disclaimer )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/jiaerxiao/scapi
// | github 代码仓库：https://github.com/jiaerxiao/scapi
// +----------------------------------------------------------------------

namespace app\system\controller;

use app\common\controller\SystemBaseController;
use app\system\facade\UserFacade;
use hg\apidoc\annotation\Author;
use hg\apidoc\annotation\Desc;
use hg\apidoc\annotation\Group;
use hg\apidoc\annotation\Method;
use hg\apidoc\annotation\Param;
use hg\apidoc\annotation\Returned;
use hg\apidoc\annotation\Sort;
use hg\apidoc\annotation\Before;

/**
 * 登录页面
 * @Group("System")
 * @Sort(1)
 */
class Login extends SystemBaseController
{
    /**
     * 初始化
     */
    public function initialize()
    {
        $this->logName = "登录页面";
        parent::initialize();
    }

    /**
     * 登录
     * @Desc("获取Token信息")
     * @Method("POST")
     * @Param("username",type="string",desc="用户名")
     * @Param("password",type="string",desc="登录密码")
     * @Before(event="handleParam",key="md5",value="params.password")
     * @Returned("token", type="string",desc="Token" )
     * @Returned("userInfo", type="array", desc="用户信息",
     *     @Returned("id", type="int", desc="唯一ID"),
     *     @Returned("avatar", type="string", desc="头像"),
     *     @Returned("userName", type="string", desc="用户名"),
     *     @Returned("name", type="string", desc="姓名"),
     *     @Returned("mail", type="string", desc="邮件"),
     *     @Returned("about", type="string", desc="签名"),
     * )
     * @Author("贾二小")
     * @since 2021/10/30
     */
    public function token()
    {
        //获取参数
        $paramData = $this->request->post(['username', 'password']);
        //参数验证
        $this->validateData($paramData);
        //登录
        $data = UserFacade::loginByAccount($paramData);
        //返回
        self::success($data);
    }
}